package com.tracesystem.dao;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tracesystem.controller.form.PorjectPageUserForm;
import com.tracesystem.controller.info.ProjectPageUserInfo;
import com.tracesystem.model.IssueProjectRoleRel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-23
 */
public interface IssueProjectRoleRelDao extends BaseMapper<IssueProjectRoleRel> {
    @Select("<script>" +
            "SELECT\n" +
            "iipr.PROJECT_ID,iipr.USER_ID,iipr.ROLE_ID,iiu.USERNAME,iir.ROLE_NAME\n" +
            "from i_issue_project_role_rel iipr\n" +
            "JOIN i_issue_user iiu\n" +
            "on iipr.USER_ID=iiu.USER_ID\n" +
            "JOIN i_issue_role iir\n" +
            "ON iir.ROLE_ID=iipr.ROLE_ID\n" +
            "where iipr.PROJECT_ID=#{pid}" +
            "<if test='key != null and key != \"\"'> " +
            " and iiu.USERNAME like CONCAT('%',#{key},'%')" +
            "</if>" +
            "</script> "
    )
    List<ProjectPageUserInfo> seleListProjectUsers(@Param("page") Page<ProjectPageUserInfo> projectPageUserInfoPage,
                                                   @Param("pid") Integer pid, @Param("key") String key);

}
